#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"
#include <math.h>
#include <stdlib.h>

#define DEBUG 0
#define NOISY_TEST 1


int checkvilliage( int player, struct gameState *post, int handPos){
    
    int r;
    struct gameState pre;
    memcpy(&pre, post, sizeof(struct gameState));
        
    r = cardEffect(village,0,0,0,post, handPos,0 );
    
    //+1 Card
    drawCard(player, &pre);
    //+2 Actions
    pre.numActions = pre.numActions + 2;
    //discard card from hand
    discardCard(handPos, player, &pre, 0);
    assert(r == 0);
    assert(post->handCount[player] == pre.handCount[player]);
    if(memcmp(&pre, post, sizeof(struct gameState)) != 0)
    
    return 0;
}

int main () {
    
    int i, n, p,  handPos;
    
    struct gameState G;
    
  printf ("Testing villiage.\n");

  printf ("RANDOM TESTS.\n");
    
    SelectStream(2);
    PutSeed(3);
    
    for (n = 0; n < 2000; n++) {
        
        for (i = 0; i < sizeof(struct gameState); i++) {
            ((char*)&G)[i] = floor(Random() * 256);
        }
        p = floor(Random() * 4);
        
        handPos = floor(Random()* 20);
        G.deckCount[p] = floor(Random() * MAX_DECK);
        G.discardCount[p] = floor(Random() * MAX_DECK);
        G.playedCardCount = floor(Random() * MAX_DECK);
        G.handCount[p] = floor(Random() * MAX_HAND);
        G.whoseTurn = p;
        G.numActions = floor(Random() * 1);
        for (i = 0; i < G.handCount[p]; i++) {
            G.hand[p][i] = floor(Random() * MAX_HAND);
        }
        for (i = 0; i < G.discardCount[p]; i++) {
            G.discard[p][i] = floor(Random() * MAX_DECK);
        }
        for (i = 0; i < G.deckCount[p]; i++) {
            G.deck[p][i] = floor(Random() * MAX_DECK);
        }
        for (i = 0; i < G.playedCardCount; i++) {
            G.playedCards[i] = floor(Random() * MAX_DECK);
        }
        
        
        checkvilliage( p, &G, handPos);
        
    }
    
    printf ("Village Card tested OK\n");
    
    
    return 0;
}